package com.example.template.common.snowflake.controller;


import com.example.template.common.snowflake.common.Result;
import com.example.template.common.snowflake.common.Status;
import com.example.template.common.snowflake.exception.LeafServerException;
import com.example.template.common.snowflake.service.SnowflakeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LeafController {
    private Logger logger = LoggerFactory.getLogger(LeafController.class);

    @Autowired
    private SnowflakeService snowflakeService;


    @RequestMapping(value = "/api/snowflake/get/{key}")
    public String getSnowflakeId() {
        return get(snowflakeService.getId());
    }

    private String get(Result id) {
        Result result;
        result = id;
        if (result.getStatus().equals(Status.EXCEPTION)) {
            throw new LeafServerException(result.toString());
        }
        return String.valueOf(result.getId());
       /* Result result = new Result();
        result.setId(1111111);
        result.setStatus(Status.EXCEPTION);
        throw new LeafServerException(result.toString());*/
    }
}
